package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 商品审核状态
 * @author Damon S.
 * @version v1.0.1
 * @date 2019年11月17日 15:36
 */
@Getter
@RequiredArgsConstructor
public enum ApprovalState {
    /**审核状态: 草稿，待审核，通过，驳回**/
    NA(-1),
    DRAFTING(0),
    REVIEWING(1),
    APPROVED(2),
    REJECTED(3);

    private final int code;

    public static ApprovalState parse(int code) {
        List<ApprovalState> filteredStates =
                Arrays.stream(ApprovalState.values())
                        .filter(state -> Objects.equals(state.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filteredStates) ? NA : filteredStates.get(0);
    }
}
